package com.funny.factoryprocessor;

import com.funny.service.TestServiceC;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author fanxiao  2021/8/10
 * @since 1.0.0
 */
@Component
public class DependencyBeanFactoryProcessor implements BeanFactoryPostProcessor {

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		ScannedGenericBeanDefinition beanDefinition =
				(ScannedGenericBeanDefinition) beanFactory.getBeanDefinition("testServiceD");

		beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
		beanFactory.ignoreDependencyInterface(TestServiceC.class);
	}
}
